TryPopRange Method (T[], Int32, Int32)

Task Parallel System.Threading

Attempts to pop and return multiple objects from the top of the ConcurrentStack<(Of <(T>)>) atomically.

Namespace:  System.Collections.Concurrent
Assembly:  System.Threading (in System.Threading.dll)

Syntax

Visual Basic (Declaration)
Public Function TryPopRange ( _
	items As T(), _
	startIndex As Integer, _
	count As Integer _
) As Integer
C#
public int TryPopRange(
	T[] items,
	int startIndex,
	int count
)

Parameters

items
Type: array< T >[]()[]
The Array to which objects popped from the top of the ConcurrentStack<(Of <(T>)>) will be added.
startIndex
Type: System..::.Int32
The zero-based offset in items at which to begin inserting elements from the top of the ConcurrentStack<(Of <(T>)>).
count
Type: System..::.Int32
The number of elements to be popped from top of the ConcurrentStack<(Of <(T>)>) and inserted into items.

Remarks

When popping multiple items, if there is little contention on the stack, using TryPopRange can be more efficient than using TryPop(T%) once per item to be removed. Nodes fill the items with the first node to be popped at the startIndex, the second node to be popped at startIndex + 1, and so on.

Exceptions

ExceptionCondition
System..::.ArgumentNullExceptionitems is a null reference (Nothing in Visual Basic).
System..::.ArgumentOutOfRangeExceptionstartIndex or count is negative. Or startIndex is greater than or equal to the length of items.
System..::.ArgumentExceptionstartIndex + count is greater than the length of items.

See Also